package delaydemo;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author chaird
 * @create 2021-10-25 11:53
 */
public class SyncProducer {
  public static void main(String[] args) throws Exception {
    // Instantiate with a producer group name.
    DefaultMQProducer producer = new DefaultMQProducer("producer_group_name");
    producer.setNamesrvAddr("localhost:9876");
    producer.start();
    System.out.println("----------------");

    String topic = "DelayDemo";
    Message msg =
            new Message(
                    topic /* Topic */,
                    "TagA" /* Tag */,
                    ("Hello RocketMQ ")/* Message body */
                            .getBytes(RemotingHelper.DEFAULT_CHARSET) );
    //private String messageDelayLevel = "1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
    msg.setDelayTimeLevel(3);//下标有0开始

    SendResult sendResult = producer.send(msg, 1000000000);
    System.out.printf("%s%n", sendResult);
    // Shut down once the producer instance is not longer in use.
    producer.shutdown();
  }
}
